/**
 * 
 */
package com.eyolas.passwordmanager.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.eyolas.passwordmanager.model.Category;
import com.eyolas.passwordmanager.utils.StringUtils;
import com.eyolas.passwordmanager.R;

/**
 * @author Eyolas
 * @date 28 mai 2012
 */
public class CategoryAdapter extends AListAdapter<Category>{

	/**
	 * @author Eyolas
	 * @date 28 mai 2012
	 * @param context
	 * @param list
	 */
	public CategoryAdapter(Context context, List<Category> list) {
		super(context, list);
	}
	
	private class ViewHolder {
		TextView categoryName;
		TextView nbAccount;
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		Category category = getItem(position);
		
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.list_category_row, null);
			
			holder.categoryName = (TextView) convertView.findViewById(R.id.categoryName);
			holder.nbAccount = (TextView) convertView.findViewById(R.id.nbAccount);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.categoryName.setText(StringUtils.ucfirst(category.getName()));
		holder.nbAccount.setText(String.valueOf(category.getNbAccount()));
		
		
		return convertView;
	}

}
